package com.hangwei.paperless.view.repair;

import com.hangwei.paperless.MainRepairActivity;

/**
 * Created by 张龙臣 on 2020/10/14.
 */

public class BreakDownRecord extends BaseMainRepairView {
    public BreakDownRecord(MainRepairActivity activity) {
        super(activity);
    }

    @Override
    protected String getTitle() {
        return "1、分解记录单 Disassembly Record Sheet";
    }

    @Override
    protected String getCurrentPage() {
        return "2";
    }

//    private static final String currentTab = "2";
//    private MainRepairAdapter mAdapter;
//    private String mCurExStep;
//    private RecyclerView mRecyclerViewPic;
//    private LinearLayout mLlDRS;
//    private HorizontalPicAdapter mPicAdapter;
//    private DRSAdapter mDRSAdapter;
//
//    private List<DRSInfo.DrsBean> mDrsList;
//    private boolean mDrsHasSaved = false;
//    private RecyclerView mRecyclerView;
//
//    public BreakDownRecord(MainRepairActivity activity) {
//        super(activity);
//    }
//
//    @Override
//    protected View initView() {
//        View inflate = LayoutInflater.from(mActivity).inflate(R.layout.page_break_down_record, null);
//        TextView tvSave = (TextView) inflate.findViewById(R.id.tvSave);
//        mRecyclerView = inflate.findViewById(R.id.recyclerView);
//        RelativeLayout rlOpen = inflate.findViewById(R.id.rlOpen);
//        rlOpen.setOnClickListener(this);
//        RecyclerView recyclerViewDRS = inflate.findViewById(R.id.recyclerViewDRS);
//        mRecyclerViewPic = inflate.findViewById(R.id.recyclerViewPic);
//        mLlDRS = inflate.findViewById(R.id.llDRS);
//        LinearLayoutManager layout = new LinearLayoutManager(mActivity);
//        layout.setOrientation(LinearLayoutManager.HORIZONTAL);
//        mRecyclerViewPic.setLayoutManager(layout);
//        mPicAdapter = new HorizontalPicAdapter(null);
//        mRecyclerViewPic.setAdapter(mPicAdapter);
//        tvSave.setOnClickListener(this);
//        recyclerViewDRS.setLayoutManager(new GridLayoutManager(mActivity, 2));
//        mDRSAdapter = new DRSAdapter();
//        recyclerViewDRS.setAdapter(mDRSAdapter);
//        mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
//        final String userId = SPUtil.getString(SPKey.Account.USER_ID);
//        mAdapter = new MainRepairAdapter(null, 0) {
//            @Override
//            protected void seal(final RecordListBean item, final int stampRole, final String resultVal) {
//                //判断是否是当前执行行
//                if (!item.id.equals(mStepId)) {
//                    return;
//                }
//                //先判断有无DRS信息
//                if (item.isDrs && 1 == stampRole && !mDrsHasSaved) {
//                    ToastUtil.showCenterToast("请先保存DRS信息！");
//                    return;
//                }
//                //选印章
//                if (App.stamps != null && App.stamps.size() > 0) {
//                    //有印章
//                    MainBottomPopupWindow mainBottomPopupWindow = mActivity.showBottomPopupWindow(BottomPopType.Seal);
//                    mainBottomPopupWindow.setOnSealListener(new MainBottomPopupWindow.OnSealListener() {
//                        @Override
//                        public void onSeal(String stampId) {
//                            final LoadingDialog loadingDialog = new LoadingDialog(mActivity);
//                            loadingDialog.show();
//                            StaticPresenter.stampRoutingSheetStep(userId, mActivity.getBillId(), item.id, stampRole, userId, stampId, resultVal, new CallBack<Object>() {
//                                @Override
//                                public void onCompleted(Object o) {
//                                    loadingDialog.dismiss();
//                                    mActivity.closeBottomPop();
//                                    initData();
//                                }
//
//                                @Override
//                                public void onError() {
//                                    loadingDialog.dismiss();
//                                }
//                            });
//                        }
//                    });
//                } else {
//                    ToastUtil.showCenterToast("无印章");
////                    String signPic = SPUtil.getString(SPKey.Account.SIGN_PIC);
////                    if (TextUtils.isEmpty(signPic)) {
////
////                    } else {
////
////                    }
//                }
//            }
//        };
//        mRecyclerView.setAdapter(mAdapter);
//        mRecyclerView.addOnItemTouchListener(new OnItemChildClickListener() {
//            @Override
//            public void onSimpleItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                if (view.getId() == R.id.ivFold) {
//                    RecordListBean recordListBean = mAdapter.getData().get(position);
//                    recordListBean.isDrsOpen = !recordListBean.isDrsOpen;
//                    ImageView ivFold = (ImageView) adapter.getViewByPosition(mRecyclerView, position, R.id.ivFold);
//                    if (recordListBean.isDrsOpen) {
//                        loadDrs(userId, recordListBean.id);
//                        for (RecordListBean bean : mAdapter.getData()) {
//                            if (!bean.id.equals(recordListBean.id)){
//                                bean.isDrsOpen = false;
//                            }
//                        }
//                        mAdapter.notifyDataSetChanged();
//                    } else {
//                        mRecyclerViewPic.setVisibility(View.GONE);
//                        mLlDRS.setVisibility(View.GONE);
//                        Animation anim = new RotateAnimation(90f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//                        anim.setFillAfter(true); // 设置保持动画最后的状态
//                        anim.setDuration(300); // 设置动画时间
//                        ivFold.startAnimation(anim);
//                    }
//                }
//            }
//        });
//        initData();
//        initBigPic();
//        return inflate;
//    }
//
//    @Override
//    public void bindData(List<RecordListBean> recordList) {
//        mAdapter.setNewData(recordList);
//    }
//
//    private void initData() {
//        mRecyclerViewPic.setVisibility(View.GONE);
//        mLlDRS.setVisibility(View.GONE);
//        mDrsHasSaved = false;
//        final LoadingDialog dialog = new LoadingDialog(mActivity);
//        dialog.show();
//        final String userId = SPUtil.getString(SPKey.Account.USER_ID);
//        StaticPresenter.getExRoutingSheetSteps(userId, mActivity.getBillId(), new CallBack<List<RecordListBean>>() {
//            @Override
//            public void onCompleted(final List<RecordListBean> recordList) {
//                bindData(recordList);
//                StaticPresenter.getRoutingSheetInfo(userId, mActivity.getBillId(), new CallBack<BasicInfoBean>() {
//                    @Override
//                    public void onCompleted(BasicInfoBean basicInfoBean) {
//                        dialog.dismiss();
//                        String[] split1 = basicInfoBean.curExStep.split("-");
//                        if (!currentTab.equals(split1[0])) {
//                            mActivity.fixedAndLoad(basicInfoBean.curExStep);
//                            return;
//                        }
//                        mCurExStep = basicInfoBean.curExStep;
//                        LogUtil.i("--------------mCurExStep------------" + mCurExStep);
//                        //对比确认当前执行行
//                        for (RecordListBean recordListBean : recordList) {
//                            LogUtil.i("recordListBean.id =    ", recordListBean.id);
//                            LogUtil.i("basicInfoBean.curExId =    ", basicInfoBean.curExId);
//                            if (recordListBean.id != null && recordListBean.id.equals(basicInfoBean.curExId)) {
//                                LogUtil.i("--------------111------------");
//                                recordListBean.isCurrent = true;
////                                if (recordListBean.id != null && !recordListBean.id.equals(mStepId)) {
////                                    mDrsHasSaved = false;//执行行改变
////                                }
//                                mStepId = recordListBean.id;
//                                if (recordListBean.isDrs||recordListBean.isPicture) {
//                                    LogUtil.i("------------2222--------------");
//                                    //获取DRS  当前折叠打开
//                                    recordListBean.isDrsOpen = true;
//                                    loadDrs(userId, mStepId);
//                                }
//                            } else recordListBean.isCurrent = false;
//                        }
//                        mAdapter.notifyDataSetChanged();
//                    }
//
//                    @Override
//                    public void onError() {
//                        dialog.dismiss();
//                    }
//                });
//            }
//
//            @Override
//            public void onError() {
//                dialog.dismiss();
//            }
//        });
//    }
//
//    private void loadDrs(String userId, String stepId) {
//        StaticPresenter.getDrsAndAttachmentList(userId, stepId, 0, new CallBack<DRSInfo>() {
//            @Override
//            public void onCompleted(DRSInfo drsInfo) {
//                initDRS(drsInfo);
//            }
//
//            @Override
//            public void onError() {
//            }
//        });
//    }
//
//    private void initDRS(DRSInfo drsInfo) {
//        if (drsInfo.attachList != null && drsInfo.attachList.size() > 0) {
//            mRecyclerViewPic.setVisibility(View.VISIBLE);
//            mPicAdapter.setNewData(drsInfo.attachList);
//        }
//        if (drsInfo.drsList != null && drsInfo.drsList.size() > 0) {
//            mLlDRS.setVisibility(View.VISIBLE);
//            mDrsList = drsInfo.drsList;
//            mDRSAdapter.setData(mDrsList);
//        }
//    }
//    private void initBigPic() {
//        mRecyclerViewPic.addOnItemTouchListener(new OnItemChildClickListener() {
//            @Override
//            public void onSimpleItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                if (view.getId()==R.id.ivScan){
//                    mActivity.showBigPic((ArrayList<String>) mPicAdapter.getData(),position);
//                }
//            }
//        });
//    }
//    @Override
//    protected void isNotFastClick(View v) {
//        switch (v.getId()) {
//            case R.id.tvSave:
//                final LoadingDialog loadingDialog = new LoadingDialog(mActivity);
//                loadingDialog.show();
//                String userId = SPUtil.getString(SPKey.Account.USER_ID);
//                String jsonData = JsonPostUtil.buildRSSaveJson(userId, mActivity.getBillId(), mStepId, mDrsList);
//                RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData);
//                StaticPresenter.saveStepDrs(requestBody, new CallBack<Object>() {
//                    @Override
//                    public void onCompleted(Object o) {
//                        mDrsHasSaved = true;
//                        ToastUtil.showCenterToast("保存成功");
//                        loadingDialog.dismiss();
//                    }
//
//                    @Override
//                    public void onError() {
//                        loadingDialog.dismiss();
//                    }
//                });
//                break;
//            case R.id.rlOpen:
//                List<RecordListBean> data = mAdapter.getData();
//                if (data.size() > 0) {
//                    final LoadingDialog dialog = new LoadingDialog(mActivity);
//                    dialog.show();
//                    String stepId = data.get(0).id;
//                    StaticPresenter.getExRoutingSheetStepByPage(mUserId, mActivity.getBillId(), "up", stepId, 5, new CallBack<List<RecordListBean>>() {
//                        @Override
//                        public void onCompleted(List<RecordListBean> listBeans) {
//                            dialog.dismiss();
//                            if (listBeans == null || listBeans.size() == 0) {
//                                ToastUtil.showCenterToast("没有数据了！");
//                            } else {
//                                List<RecordListBean> beans = mAdapter.getData();
//                                beans.addAll(0, listBeans);
//                                mAdapter.setNewData(beans);
//                            }
//                        }
//
//                        @Override
//                        public void onError() {
//                            dialog.dismiss();
//                        }
//                    });
//                }
//                break;
//        }
//    }

}
